#include<bits/stdc++.h>
using namespace std;

void solution(string star, string group)
{
	int sum1 = 1, sum2 = 1;
	for(auto i : star)
		sum1 = (sum1%47)*int(i-'A'+1);
	for(int i : group)
		sum2 = (sum2%47)*int(i-'A'+1);
	sum1 %= 47;
	sum2 %= 47;
	if(sum1 == sum2)
		cout<<"GO";
	else
		cout<<"STAY"; 
}

int main()
{
	string s1, s2;
	cin>>s1>>s2;
	solution(s1, s2);
	return 0;
}

